<script setup>
import { ref, onMounted } from 'vue'
import { getRecentPurchaseAPI } from '@/apis/purchase'

const purchaseList = ref([])
onMounted(async () => {
    const res = await getRecentPurchaseAPI()
    // console.log(res);
    if (res.code === 2000) {
        purchaseList.value = res.data
    }
})
</script>

<template>
<div class="purchase-container">
    <div class="container-header">
        <div class="title">近日采购</div>
        <div class="more"><a href="#">更多</a></div>
    </div>
    <div class="purchase-list">
        <div class="list-header">
            <div class="col-1">采购名称</div>
            <div class="col-2">采购数量</div>
            <div class="col-3">采购说明</div>
            <div class="col-4">期望来源地</div>
            <div class="col-5">采购方</div>
            <div class="col-6">发布时间</div>
            <div class="col-7">操作</div>
        </div>
        <template v-for="purchase in purchaseList" :key="purchase.id">
            <RouterLink :to="`/purchaseDetail/${purchase.id}`" class="list-item">
                <div class="col col-1">{{ purchase.name }}</div>
                <div class="col col-2">{{ purchase.amount }}{{ purchase.unit }}</div>
                <div class="col col-3">{{ purchase.comment }}</div>
                <div class="col col-4">{{ purchase.origin }}</div>
                <div class="col col-5">{{ purchase.user }}</div>
                <div class="col col-6">{{ purchase.publishTime.split(' ')[0] }}</div>
                <div class="col col-7"><a href="javascript:;">查看详情</a></div>
            </RouterLink>
        </template>
    </div>
</div>
</template>

<style scoped lang='scss'>
.purchase-container {
    width: 1280px;
    padding: 20px 30px;
    margin: 20px auto;
    margin-bottom: 30px;
    background-color: #fff;

    .container-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 15px;
        margin-bottom: 15px;
        border-bottom: 1px solid #f4f4f4;

        .title {
            width: 100px;
            font-size: 20px;
            font-weight: bold;
        }

        .more {
            width: 80px;
            
            >a {
                color: #646464;
                font-size: 12px;
            }
        }
    }

    .purchase-list {
        width: 100%;
        padding-left: 40px;
        padding-right: 55px;
        min-height: 200px;
        border-bottom: 1px solid #f4f4f4;

        .list-header {
            display: flex;
            justify-content: space-between;
            padding-bottom: 10px;
            user-select: none;
            border-bottom: 1px solid #f4f4f4;

            >div {
                font-size: 14px;
                font-weight: bold;
            }
        }

        .list-item {
            display: flex;
            justify-content: space-between;
            font-size: 14px;
            margin: 15px 0;

            &:hover {
                background: #fbfbfb;

                .col-7>a {
                    color: #fff;
                    background-color: #39bf3e;
                }
            }
        }

        .col {
            height: 25px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .col-1 {
            width: 120px;
        }
        .col-2 {
            width: 100px;
        }
        .col-3 {
            width: 240px;
        }
        .col-4 {
            width: 180px;
        }
        .col-5 {
            width: 120px;
        }
        .col-6 {
            width: 120px;
        }
        .col-7 {
            text-align: center;
            width: 80px;

            >a {
                display: block;
                font-size: 12px;
                color: #39bf3e;
                border: 1px solid #39bf3e;
                padding: 3px 10px;
                transition: all .2s;
            }
        }
    }
}
</style>
